package com.anytrek.demomqtt.config;

import lombok.extern.log4j.Log4j2;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.MessagingException;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;

@Component
@Log4j2
public class ReceiverMessageHandler implements MessageHandler {

    @Override
    public void handleMessage(Message<?> mqttMessage) throws MessagingException {
        String message = mqttMessage.getPayload().toString();
        MessageHeaders headers = mqttMessage.getHeaders();
        Object topic = headers.get("mqtt_receivedTopic");
        log.info("MQTT<-----receive topic : {}, ReceiveMessage : {}", topic, message);
    }
}